package com.region.b.service;

import cn.hutool.core.thread.ThreadUtil;
import com.region.b.service.itf.B1002_ITF;
import com.syf.core.service.SyService;
import com.syf.core.service.SyServiceSetting;
import com.syf.core.service.context.ServiceContext;
import com.syf.kit.SyIdGenerator;
import com.syf.kit.SyfJsonMapperFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@SyServiceSetting(code = "B1002", desc = "test-region-调用故意超时")
public class B1002 implements SyService<B1002_ITF.ReqData, B1002_ITF.RespData> {

    @Override
    public void execute(ServiceContext<B1002_ITF.ReqData, B1002_ITF.RespData> ctx) {
        log.info("交易码为{}", ctx.getRequest().getHead().getServiceDefinition().getServiceCode());

        B1002_ITF.ReqData reqDataObj = ctx.getRequest().getDataObj();

        SyfJsonMapperFactory jsonMapperFactory = ctx.getToolKit(SyfJsonMapperFactory.class);
        log.info("请求报文的json字符串为{}", jsonMapperFactory.getUnifiedJsonMapper().toJsonString(reqDataObj));

        SyIdGenerator idGenerator = ctx.getToolKit(SyIdGenerator.class);
        log.info("生成一个id：{}", idGenerator.getSyStrategySeqNo());

        // 模拟超时
        ThreadUtil.sleep(31000);

        ctx.getResponse().setSuccess();
        ctx.getResponse().setDataObj(new B1002_ITF.RespData("超时成功！"));
    }
}